package com.duofan.gmall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

//@Data
public class OrderConfirmVo {

    /** 收获地址列表 */
    List<MemberAddressVo> address;
    /** 所有选中的购物项 */
    List<OrderItemVo> items;
    /** 发票记录... */

    /** 优惠券信息... */
    Integer integration;
    /** 订单总额 */
//    BigDecimal total;
    /** 应付价格 */
    BigDecimal payPrice;

    Map<Long, Boolean> stocks;

    /** 防重令牌 */
    @Getter @Setter
    String orderToken;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if(!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                BigDecimal itemTotalPrice = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(itemTotalPrice);
            }
        }
        return sum;
    }

    /**
     * 商品总数量
     * @return
     */
    public Integer getCount() {
        Integer count = 0;
        if(!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Map<Long, Boolean> getStocks() {
        return stocks;
    }

    public void setStocks(Map<Long, Boolean> stocks) {
        this.stocks = stocks;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }
}
